package com.wlz.rocketmq.simple;

import com.wlz.rocketmq.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.common.message.MessageQueue;

/**
 * @author wlz
 * @date 2022-07-01  9:57 下午
 */
@Slf4j
public class PullConsumer2 {

    public static void main(String[] args) throws Exception{
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");

        consumer.setNamesrvAddr(Constants.NAMESVADDR);

        consumer.start();

        try {
            MessageQueue mq = new MessageQueue();
            mq.setQueueId(0);
            mq.setTopic("TopicTest");
            mq.setBrokerName("broker-a");

            long offset = 26;

            long beginTime = System.currentTimeMillis();

            PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);

            log.info(" time: {}", System.currentTimeMillis() - beginTime);

            log.info(" pullResult: {} ", pullResult);
        } catch (Exception e) {
            log.info(" PullConsumer2 error: {}", e);
        }

        consumer.shutdown();

    }
}
